<!DOCTYPE html>
<html lang="cn">
<head>
    <title>WSD Admin</title>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="stylesheet" href="__STATICURL__/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="__STATICURL__/css/bootstrap-responsive.min.css"/>
    <link rel="stylesheet" href="__STATICURL__/css/uniform.css"/>
    <link rel="stylesheet" href="__STATICURL__/css/select2.css"/>
    <link rel="stylesheet" href="__STATICURL__/css/matrix-style.css"/>
    <link rel="stylesheet" href="__STATICURL__/css/matrix-media.css"/>
    <link rel="stylesheet" href="__STATICURL__/css/bootstrap-wysihtml5.css"/>
    <link href="__STATICURL__/font-awesome/css/font-awesome.css" rel="stylesheet"/>
</head>
<body>
<include file="Common:header"/>
<div id="content">
    <!--breadcrumbs-->
    <div id="content-header">
        <div id="breadcrumb"><a href="__ROOT__/clover"><i class="icon-home"></i> 主页</a>
            <a href="__URL__">产品列表</a><a href="#" class="current">产品添加</a>
        </div>
    </div>
    <!--End-breadcrumbs-->
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box" style="margin-top:0px;">
                    <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                        <h5>添加产品</h5>
                    </div>
                    <div class="widget-content nopadding">
                        <table class="table table-bordered table-striped">
                            <tbody>
                            <tr class="odd gradeX">
                                <td>产品题目</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_name}"
                                               class="book_name" placeholder="输入产品题目"/>
                                    </div>
                                </td>

                                <td>产品类型</td>
                                <td style="border-left:none;">
                                    <div class="control-group fl" style="width:200px;">
                                        <div class="controls" style="width:301px;">
                                            <select id="cat_id">
                                                <option value=0>-----选择产品分类-----</option>
                                                <foreach name="{category_list}" item="row">
                                                    <notempty name="row.p_level">
                                                        <option
                                                        <if condition="$book_info.cat_id eq $row.id ">selected</if>
                                                        style="padding-left:{$row[p_level]*30}px;" value="{$row.id}">
                                                        <for start="0" end="$row.p_level">&nbsp;&nbsp;&nbsp;</for>
                                                        {$row.cat_name}</option>
                                                        <else/>
                                                        <option
                                                        <if condition="$book_info.cat_id eq $row.id ">selected</if>
                                                        style="font-weight:bold;"
                                                        value="{$row.id}">{$row.cat_name}</option>
                                                    </notempty>
                                                </foreach>
                                            </select>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr class="odd gradeX">
                                <td>产品售价</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_price}"
                                               value="0" class="book_price" placeholder="售价"/>
                                    </div>
                                </td>
                                <td>产品原价</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_base_price}"
                                               value="0" class="book_base_price" placeholder="原价"/>
                                    </div>
                                </td>
                            </tr>
                            <tr class="odd gradeX">
                                <td>厂商</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_press}"
                                               class="book_press" placeholder="厂商"/>
                                    </div>
                                </td>
                                <td>生产日期</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_press_time}"
                                               class="book_press_time" placeholder="生产日期"/>
                                    </div>
                                </td>
                            </tr>
                            <!--<tr class="odd gradeX">-->
                            <!--<td>页码</td>-->
                            <!--<td style="border-left:none;">-->
                            <!--<div class="controls"  >-->
                            <!--<input style="width:258px;" type="text"  value="{$book_info.book_page}" class="book_page" placeholder="页码" />-->
                            <!--</div>-->
                            <!--</td>-->
                            <!--<td>开本</td>-->
                            <!--<td style="border-left:none;">-->
                            <!--<div class="controls"  >-->
                            <!--<input style="width:258px;" type="text" value="{$book_info.book_size}" class="book_size" placeholder="开本" />-->
                            <!--</div>-->
                            <!--</td>-->
                            <!--</tr>-->

                            <tr class="odd gradeX">
                                <td>产品ISBN</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_isbn}"
                                               class="book_isbn" placeholder="ISBN"/>
                                    </div>
                                </td>
                                <td>产品排序</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="0" class="sort_order"
                                               placeholder="值越大越靠前"/>
                                    </div>
                                </td>
                            </tr>
                            <tr class="odd gradeX">
                                <td>产品员工</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_author}"
                                               class="book_author" placeholder="员工姓名"/>
                                    </div>
                                </td>
                                <td>产品链接</td>
                                <td style="border-left:none;">
                                    <div class="controls">
                                        <input style="width:258px;" type="text" value="{$book_info.book_link}"
                                               class="book_link" placeholder="添加链接"/>
                                    </div>
                                </td>
                            </tr>


                            <tr class="odd gradeX">
                                <td>产品图片</td>
                                <td colspan="4" style="border-left:none;">
                                    <div class=" fl">
                                        <span id="J_morepic_upload"></span>
                                        <input type="hidden" value="{$book_info.book_img}" id="J_pic_url">
                                    </div>
                                    <div class="widget-content  fl" style="border:none;padding:0;">
                                        <ul class="thumbnails picList">
                                            <li class="span2 li_place" style="width:170px;height:73px;">
                                                <a> <img src="__UPLOADURL__/{$book_info.book_img}" alt=""
                                                         style="height:100px"> </a>

                                                <div class="actions">
                                                    <a title="" data-id='{$book_info.id}' class="J_delete"
                                                       href="javascript:void(0);">
                                                        <i class="icon-remove"></i>
                                                    </a>
                                                    <a class="lightbox_trigger"
                                                       href="__UPLOADURL__/{$book_info.book_img}">
                                                        <i class="icon-search"></i>
                                                    </a>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            <tr class="odd gradeX">
                                <td>产品简介</td>
                                <td colspan="4" style="border-left:none;">
                                    <div class="controls">
                                        <script id="contents" type="text/plain" style="width:99%;height:250px;">
                                            {$book_info['book_intro']}
                                        </script>
                                    </div>
                                </td>
                            </tr>

                            <tr>
                                <td></td>
                                <td style="border-left:none;">
                                    <button type="" class="btn btn-success J_submit">保存</button>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--Footer-part-->
<include file="Common:footer"/>
<!--end-Footer-part-->
<script src="__STATICURL__/js/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATICURL__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATICURL__/js/ueditor/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATICURL__/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script src="__STATICURL__/js/jquery.ui.custom.js"></script>
<script src="__STATICURL__/js/bootstrap.min.js"></script>
<script src="__STATICURL__/js/jquery.uniform.js"></script>
<script src="__STATICURL__/js/select2.min.js"></script>
<script src="__STATICURL__/js/jquery.dataTables.min.js"></script>
<script src="__STATICURL__/js/matrix.js"></script>
<script src="__STATICURL__/js/matrix.tables.js"></script>

<script src="__STATICURL__/js/swfupload.js"></script>
<script src="__STATICURL__/js/swfupload.queue.js"></script>
<script src="__STATICURL__/js/fileprogress.js"></script>
<script src="__STATICURL__/js/handlers.js"></script>
</body>
</html>
<script type="text/javascript">
    var ue = UE.getEditor('contents');
    $(document).ready(function () {
        $(".J_submit").click(function (event) {
            var id = {$book_info.id};
        var book_name = $(".book_name").val();
        var cat_id = $("#cat_id").val();
        var book_price = $(".book_price").val();
        var book_base_price = $(".book_base_price").val();
        var book_press = $(".book_press").val();
        var book_press_time = $(".book_press_time").val();
        var book_page = $(".book_page").val();
        var book_size = $(".book_size").val();
        var book_isbn = $(".book_isbn").val();
        var sort_order = $(".sort_order").val();
        var book_author = $(".book_author").val();
        var book_link = $(".book_link").val();
        var book_intro = UE.getEditor('contents').getContent();
        var book_img = $("#J_pic_url").val();
        if (book_name == "") {
            alert("输入产品题目");
            $(".book_name").focus();
            return false;
        }
        if (book_intro == '') {
            alert("请输入产品内容！");
            book_intro.focus();
            return;
        }
        $.post('__URL__/do_edit', {
            id: id,
            book_name: book_name,
            cat_id: cat_id,
            book_price: book_price,
            book_base_price: book_base_price,
            book_press: book_press,
            book_press_time: book_press_time,
            book_page: book_page,
            book_size: book_size,
            book_isbn: book_isbn,
            sort_order: sort_order,
            book_intro: book_intro,
            sort_order: sort_order,
            book_img: book_img,
            book_author: book_author,
            book_link: book_link
        }, function (res) {
            if (res) {
                alert("成功");
                window.location.href = "__URL__/index";
            } else {
                alert("修改失败");
            }
        });
    });

    var settings = {
        flash_url: "__STATICURL__/js/swfupload.swf",
        upload_url: "__URL__/upload_cover",
        post_params: {"is_more": "yes"},
        file_size_limit: "100 MB",
        file_types: "*.jpg;*.gif;*.png;",
        file_upload_limit: 100,
        file_queue_limit: 100,
        custom_settings: {
            progressTarget: "fsUploadProgress",
            cancelButtonId: "btnCancel"
        },
        debug: false,
        // Button settings
        button_width: "114",
        button_height: "32",
        button_placeholder_id: "J_morepic_upload",
        button_text_style: ".theFont { font-size: 16;}",
        button_cursor: -2,
        button_window_mode: "TRANSPARENT",
        button_action: -100,//-110多图片上传，-100但图片上传，-120文件上传
        button_image_url: "__STATICURL__/images/upload_place.png",

        file_queued_handler: fileQueued,
        file_queue_error_handler: fileQueueError,
        file_dialog_complete_handler: fileDialogComplete,
        upload_start_handler: banner_uploadStart,
        upload_progress_handler: uploadProgress,
        upload_error_handler: uploadError,
        upload_success_handler: uploadCompleteProduct,
        upload_complete_handler: uploadComplete
    };
    swfu = new SWFUpload(settings);

    $(".J_delete").live("click", function (event) {
        var id = $(this).attr("data-id");
        $.post('__URL__/do_delete_pic', {id: id}, function (res) {
            if (res) {
                $(".li_place").fadeOut("fast");
                $("#J_pic_url").val("");
            }
        }, "json");
    });
    });

    function uploadCompleteProduct(file, server_data, receivedResponse) {
        var pic_url = server_data.substr(0,28);
        $("#J_pic_url").val(pic_url);
    }
</script>
